package org.openoa.antreport.config;

import com.bstek.ureport.UReportPropertyPlaceholderConfigurer;
import com.bstek.ureport.console.UReportServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;

import javax.servlet.Servlet;

@Configuration
@ImportResource("classpath:ureport-console-context.xml")
@PropertySource("classpath:application.properties")
public class AntReportServletConfig {

    @Bean
    public ServletRegistrationBean<Servlet> ureportServlet() {
        return new ServletRegistrationBean<>(new UReportServlet(), "/antreport/*");
    }

    // 使用web项目里面的配置
    @Bean
    public static UReportPropertyPlaceholderConfigurer propertyConfigurer() {
        UReportPropertyPlaceholderConfigurer configurer = new UReportPropertyPlaceholderConfigurer();
        configurer.setIgnoreUnresolvablePlaceholders(true);
        configurer.setLocation(new ClassPathResource("application.properties"));
        return configurer;
    }
}
